//01背包

#include <iostream>
#include <vector>
#include <cstring>
using namespace std;

int main() {
    int n, V;
    cin >> n >> V;
    vector<int> v(n + 1);
    vector<int> w(n + 1);
    for(int i = 1; i <= n; i++)
    {
        cin >> v[i] >> w[i];
    }
    vector<vector<int>> dp(n + 1, vector<int>(V + 1, 0));
    for(int i = 1; i <= n; i++)
    {
        for(int j = 1; j <= V; j++)
        {
            dp[i][j] = dp[i - 1][j];
            if(v[i] <= j) dp[i][j] = max(dp[i][j], w[i] + dp[i - 1][j - v[i]]);
        }
    }
    cout << dp[n][V] <<endl;
    
    for(int i = 1; i <= n; i++)
    {
        for(int j = 1; j <= V; j++)
        {
            dp[i][j] = 0;
        }
    }
    for(int j = 1; j <= V; j++)
    {
        dp[0][j] = -1;
    }
    for(int i = 1; i <= n; i++)
    {
        for(int j = 1; j <= V; j++)
        {
            dp[i][j] = dp[i - 1][j];
            if(v[i] <= j && dp[i - 1][j - v[i]] != -1) dp[i][j] = max(dp[i][j], w[i] + dp[i - 1][j - v[i]]);
        }
    }
    cout << (dp[n][V] == -1 ? 0 : dp[n][V]) <<endl;
}
